﻿package mortal.game.view.common.guide.stepOperater
{
    import com.gengine.keyBoard.*;
    import com.mui.utils.*;
    import flash.events.*;
    import flash.utils.*;
    import mortal.component.window.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.guide.data.*;
    import mortal.game.view.common.guide.view.*;
    import mortal.mvc.core.*;

    public class AutoGuidePlayerRolling extends Object implements IAutoGuideSteper
    {
        private var _data:AutoGuideData;
        private var _win:AutoGuidePictureWin;
        private var _timer:Timer;

        public function AutoGuidePlayerRolling()
        {
            return;
        }// end function

        public function guide(param1:AutoGuideData, param2:Window = null) : void
        {
            if (this._timer != null)
            {
                this.stop();
            }
            this._data = param1;
            if (this._win == null)
            {
                this._win = UICompomentPool.getUICompoment(AutoGuidePictureWin);
            }
            this._win.callback = this.clickISeeHandler;
            this._win.show();
            this._win.autoGuideData = param1;
            if (this._timer == null)
            {
                this._timer = new Timer(7500);
                this._timer.addEventListener(TimerEvent.TIMER, this.onTimer);
            }
            this._timer.start();
            return;
        }// end function

        private function clickISeeHandler(param1:int = 1) : void
        {
            this.onTimer(null);
            return;
        }// end function

        private function onTimer(event:TimerEvent) : void
        {
            this.stop(this._data);
            return;
        }// end function

        private function onKeyDownHandler(event:KeyEvent) : void
        {
            if (event == null || event.keyData == null || event.keyData.keyMap == null)
            {
                return;
            }
            if (event.keyData.keyMap.key == ModuleType.SPACE)
            {
                this.stop(this._data);
            }
            return;
        }// end function

        public function stop(param1:AutoGuideData = null) : void
        {
            if (this._timer != null)
            {
                this._timer.stop();
                this._timer = null;
            }
            if (this._win != null)
            {
                this._win.hide();
                this._win = null;
            }
            if (param1 != null)
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.AutoGuideStepEnd, param1));
            }
            return;
        }// end function

    }
}
